package com.onlinefurnitureshop.management.service.impl;

import java.util.List;
import java.util.Set;

import com.onlinefurnitureshop.management.dao.UsersDao;
import com.onlinefurnitureshop.management.model.Users;
import com.onlinefurnitureshop.management.service.RoleService;
import com.onlinefurnitureshop.management.service.UsersService;
import com.onlinefurnitureshop.shiro.PasswordHelper;

public class UsersServiceImpl implements UsersService{
	
	private UsersDao usersDao;
	private RoleService roleService;
	private PasswordHelper passwordHelper;
	
	
	

	public PasswordHelper getPasswordHelper() {
		return passwordHelper;
	}

	public void setPasswordHelper(PasswordHelper passwordHelper) {
		this.passwordHelper = passwordHelper;
	}

	public UsersDao getUsersDao() {
		return usersDao;
	}

	public void setUsersDao(UsersDao usersDao) {
		this.usersDao = usersDao;
	}

	public RoleService getRoleService() {
		return roleService;
	}

	public void setRoleService(RoleService roleService) {
		this.roleService = roleService;
	}

	@Override
	public Users createUser(Users user) {
		// TODO Auto-generated method stub
		passwordHelper.encryptPassword(user);
		return usersDao.createUser(user);
	}

	@Override
	public Users updateUser(Users user) {
		// TODO Auto-generated method stub
		return usersDao.updateUser(user);
	}

	@Override
	public void deleteUser(Long userId) {
		// TODO Auto-generated method stub
		usersDao.deleteUser(userId);
	}

	@Override
	public Users findOne(Long userId) {
		// TODO Auto-generated method stub
		return usersDao.findOne(userId);
	}

	@Override
	public List<Users> findAll() {
		// TODO Auto-generated method stub
		return usersDao.findAll();
	}

	@Override
	public Users findByUsername(String username) {
		// TODO Auto-generated method stub
		return usersDao.findByUsername(username);
	}

	@Override
	public String findRole(String username) {
		// TODO Auto-generated method stub
		Users user = findByUsername(username);
		if(user == null)
			return null;
 		return roleService.findOne(user.getRoleId()).getRole();
	}

	@Override
	public Set<String> findPermissions(String username) {
		// TODO Auto-generated method stub
		Users user = findByUsername(username);
		if(user == null)
			return null;
 		return roleService.findPersmissions(user.getRoleId());
	}

}
